#include<stdio.h>
#include<conio.h>
#include<time.h>
long long n,num[5001]={1},k=0,u;
long long value[5001];
long long getleft(long long begin,long long max){//Lay so cuoi cung con nho hon (hay bang)
    if(value[k]<=max)return k;
    if(value[begin]>max)return 0;
    int tg,f=begin,l=k;
    do{
        
        tg=(f+l)/2;
        if(value[tg]==max)return tg;
        if(value[tg]>max)l=tg;
        else f=tg;
    }while(l-f>=2);
    if(value[l]<=max)return l;
    else if(value[f]<=max)return f;
    else return f-1;
}
void input(){
    long long i,j,t;
    FILE *fp=fopen("TRIANGLES.INP","r");
    fscanf(fp,"%lld",&n);
    for(i=1;i<=n;i++){
        fscanf(fp,"%lld",&u);
        j=getleft(1,u);
        if(value[j]==u)num[j]++;
        else{
             k++;
             j++;
             for(t=k;t>j;t--){
                num[t]=num[t-1];
                value[t]=value[t-1];
            }
            value[j]=u;
        }
    }
    fclose(fp);
}
long long tamgiacthuong(){
    long long n=0,left=0;
    for(long long i=1;i<k-1;i++)
        for(long long j=i+1;j<k;j++){
            left=getleft(j+1,value[j]+value[i]-1);
            if(left>j)n+=left-j;
        }
    return n;
}
long long tamgiacphithuong(){
    long long i,deu=0,can=0,left;
    for(i=1;i<=k;i++){
        if(num[i]>=3)deu++;
        if(num[i]>=2){
            left=getleft(1,value[i]*2-1);
            can+=left;
            if(left>=i)can--;
        }
    }
    return deu+can;
}
void output(long long k){
    FILE *fp=fopen("TRIANGLES.OUT","w");
    fprintf(fp,"%lld",k);
    fclose(fp);
}
int main(){
    input();
    output(tamgiacthuong()+tamgiacphithuong());
    return 0;
}
            
